Skip to content

gh-145260: fix ResourceContainer/ResourceHandle for Traversable changes#145263

Open
zetzschest wants to merge 5 commits intopython:mainfrom
zetzschest:fix/importlib_simple_resource_traversable
Open

gh-145260: fix ResourceContainer/ResourceHandle for Traversable changes#145263
zetzschest wants to merge 5 commits intopython:mainfrom
zetzschest:fix/importlib_simple_resource_traversable

Conversation

@zetzschest
Copy link

@zetzschest zetzschest commented Feb 26, 2026

Problem

ResourceContainer and ResourceHandle cannot be instantiated because Traversable now requires name as an abstract property. Also, iterdir() accesses self.reader.resources without calling it, and ResourceHandle.joinpath has a signature mismatch.

Reproducer

from importlib.resources.simple import ResourceContainer, SimpleReader
import io

class R(SimpleReader):
    @property
    def package(self): return 'x'
    def children(self): return []
    def resources(self): return []
    def open_binary(self, r): return io.BytesIO(b'')

ResourceContainer(R())  # TypeError

Fix

  • Add name property to ResourceContainer and ResourceHandle
  • Add iterdir to ResourceHandle
  • Fix self.reader.resourcesself.reader.resources() in ResourceContainer.iterdir()
  • Fix ResourceHandle.joinpath to accept *descendants

@bedevere-app
Copy link

bedevere-app bot commented Feb 26, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@zetzschest zetzschest marked this pull request as ready for review February 26, 2026 15:47
@zetzschest zetzschest force-pushed the fix/importlib_simple_resource_traversable branch from b7cc205 to efdc545 Compare February 26, 2026 17:43
@zetzschest zetzschest changed the title gh-145260: fix(importlib.resources.simple): Make ResourceContainer and ResourceH… gh-145260: fix ResourceContainer/ResourceHandle for Traversable changes Feb 26, 2026
@ericvsmith ericvsmith self-requested a review February 27, 2026 12:24
Copy link
Member

@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked at the PR in detail, but please add tests so we can ensure this keeps working.

@bedevere-app
Copy link

bedevere-app bot commented Feb 27, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

zetzschest and others added 3 commits February 27, 2026 13:28
… ResourceHandle

ResourceContainer and ResourceHandle could not be instantiated because
Traversable now requires name as an abstract property. Additionally,
ResourceContainer.iterdir() accessed self.reader.resources without
calling it, and ResourceHandle.joinpath had a signature mismatch.

- Add name property to ResourceContainer
- Fix self.reader.resources -> self.reader.resources() call
- Add iterdir() method to ResourceHandle
- Fix ResourceHandle.joinpath to accept *descendants
Add tests for ResourceContainer and ResourceHandle classes to verify:
- ResourceContainer instantiation with name property
- ResourceContainer.iterdir() calling resources() method
- ResourceHandle.joinpath() accepting *descendants parameter
- ResourceHandle.iterdir() returning empty iterator
- ResourceHandle name as property instead of instance variable

Also fix ResourceHandle.name to be a property to satisfy Traversable
abstract base class requirements.
@zetzschest zetzschest force-pushed the fix/importlib_simple_resource_traversable branch from 38aab31 to d95ab35 Compare February 27, 2026 13:28
@ZeroIntensity ZeroIntensity removed their request for review February 27, 2026 14:30
@picnixz picnixz removed their request for review February 27, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants